package reggie.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import reggie.common.JacksonObjectMapper;

import java.util.List;

@Slf4j
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
//    /**
//     * 静态资源映射
//     * @param registry
//     */


    //
    //@Override
    //public void addResourceHandlers(ResourceHandlerRegistry registry) {
    //    log.info("开始资源映射...");
    //    registry.addResourceHandler("/backend/**").addResourceLocations("classpath:/static/backend/");
    //    log.info("{}-->{}", "/static/backend/**", "classpath*:/backend/");
    //    registry.addResourceHandler("/front/**").addResourceLocations("classpath:/front/");
    //    log.info("{}-->{}", "/front/**", "classpath:/front/");
    //
    //}

    /**
     * mvc消息转换
     * @param converters
     */
    public void configureMessageConverters(List<HttpMessageConverter<?>> converters){
        MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter = new MappingJackson2HttpMessageConverter();
        mappingJackson2HttpMessageConverter.setObjectMapper(new JacksonObjectMapper());
        converters.add(0, mappingJackson2HttpMessageConverter);
    }

    //@Override
    // void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
    //    MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter = new MappingJackson2HttpMessageConverter();
    //    mappingJackson2HttpMessageConverter.setObjectMapper(new JacksonObjectMapper());
    //    converters.add(0, mappingJackson2HttpMessageConverter);
    //}

    /**
     * 扩展mvc消息转换器
     * @param converters
     */
    //@Override
    //public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
    //
    //}
}
